package com.niit.session15;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

//用于验证手机号和邮箱是否符合规范
public class Validate {
	
	private static final String EMAIL = "[a-zA-Z0-9]+@[a-zA-Z0-9]+.[a-zA-Z0-9]+";
	private static final String PHONE = "^1[3-9]\\d{9}$";
	/**
	 * 验证邮箱是否符合规范
	 * @param email 要验证的邮箱
	 * @return
	 */
	public static boolean isEmail(String email) {
		Pattern pattern = Pattern.compile(EMAIL);
//		验证传进来的字符串是否是一个邮箱
		Matcher matcher = pattern.matcher(email);
		boolean isEmail = matcher.matches();
		return isEmail;
	}
	/**
	 * 验证手机号码是否符合规范
	 * @param phone 要验证的手机号
	 * @return
	 */
	public static boolean isPhone(String phone) {
		Pattern pattern = Pattern.compile(PHONE);
//		验证传进来的字符串是否是一个手机号
		Matcher matcher = pattern.matcher(phone);
		boolean isPhone = matcher.matches();
		return isPhone;
	}

}
